package com.gs.synedocket.adapter;

import android.content.Context;
import android.widget.TextView;

import com.gs.synedocket.R;
import com.gs.synedocket.adapter.base.BaseAdapter;
import com.gs.synedocket.adapter.base.BaseViewHolder;
import com.gs.synedocket.db.dto.ShortDto;

import java.util.List;

public class TruckAdapter extends BaseAdapter<ShortDto> {

    public TruckAdapter(Context context, List<ShortDto> list, int layoutId) {
        super(context, list, layoutId);
    }

    @Override
    public void convert(BaseViewHolder holder, ShortDto item, int position) {
        TextView tv = holder.fd(R.id.tv_dialog);
        tv.setText(item.getName() == null ? "" : item.getName());
        tv.setSelected(item.getDef() != null ? item.getDef() : false);
    }

    public void changeState(int position) {
        ShortDto dto = list.get(position);
        if (dto.getDef() != null && dto.getDef()) {
            return;
        }
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setDef(false);
        }
        list.get(position).setDef(true);
        notifyDataSetChanged();
    }
}
